/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 洪汤泽大帅哥
 * Date: 2024-11-17
 * Time: 20:07
 */
public class Main {

    public static int countSegments(String s) {
        int count = 0;
        String ret = s.trim();
        for (int i = 0; i < ret.length(); i++) {
            if (i==0||ret.charAt(i-1)==' '&&ret.charAt(i)!=' '){
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        String string = "Hello, my name is John";
        System.out.println(countSegments(string));
    }
}
